/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PDFpacket;

import Utils.User;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import servlets.BuyerAscoltaConferma;

/**
 *
 * @author Alice
 */
public class Pdf_RicevutaP {
    public void Genera(String pr,float f,String u,String c,String id,int q,HttpServletRequest request,HttpServletResponse response,String Percorso,String nameBuyer) throws DocumentException, FileNotFoundException{
        
        ServletContext ctx=request.getServletContext();
        String contextPath=ctx.getRealPath(File.separator);
    
       //CREA CARTELLA
        
        File file= new File(contextPath+"PDF/"+nameBuyer+"/");
        if(!file.exists()){
            file.mkdir();
        }
        
        
        try{ 
           
        Document pdfRicevuta = new Document();
        PdfWriter.getInstance(pdfRicevuta , new FileOutputStream(contextPath+"PDF/"+nameBuyer+"/"+Percorso));
        pdfRicevuta.open();
        Paragraph p = new Paragraph("--Ricevuta--", FontFactory.getFont(FontFactory.HELVETICA,18));
        p.setAlignment(Element.ALIGN_CENTER);
        pdfRicevuta.add(p);
        Paragraph p2 = new Paragraph("Ecco qui la ricevuta del prodotto aquistato.", FontFactory.getFont(FontFactory.HELVETICA,18));
        p2.setAlignment(Element.ALIGN_LEFT);
        pdfRicevuta.add(p2);
        Paragraph p3 = new Paragraph("     ");
        p.setAlignment(Element.ALIGN_CENTER);
        pdfRicevuta.add(p3);
        //DATI
        List list = new List(false, 20);
        list.setListSymbol(new Chunk("\u2022",
        FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)));
        ListItem listItem = new ListItem(" Seller : "+id);
        list.add(listItem);
        ListItem listItem2 = new ListItem(" Product : "+pr);
        list.add(listItem2);
        ListItem listItem3 = new ListItem(" Price : "+f);
        list.add(listItem3);
        ListItem listItem4 = new ListItem(" UM (Unità di Misura) : "+u);
        list.add(listItem4);
        ListItem listItem5 = new ListItem(" Quantity : "+q);
        list.add(listItem5);
        ListItem listItem6 = new ListItem(" Category : "+c);
        list.add(listItem6);


        pdfRicevuta.add(list);
        pdfRicevuta.add(p3);
        //CHIUSURA
        Paragraph p4 = new Paragraph("Grazie dell'acquisto!", FontFactory.getFont(FontFactory.HELVETICA,16));
        p3.setAlignment(Element.ALIGN_LEFT);
        pdfRicevuta.add(p4);
        Paragraph p5 = new Paragraph("A presto.", FontFactory.getFont(FontFactory.HELVETICA,16));
        p4.setAlignment(Element.ALIGN_LEFT);
        pdfRicevuta.add(p5);
        pdfRicevuta.close();
        
    } catch (DocumentException ex) {
            Logger.getLogger(BuyerAscoltaConferma.class.getName()).log(Level.SEVERE, null, ex);
    }
}}
